#include<bits/stdc++.h>
using namespace std;
#define int long long

char a[100][100];

signed main() {
	int n, m;
	cin >> n >> m;
	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= m; j++)
			cin >> a[i][j];

	int ans = INT_MAX;
	for (int i = 1; i < n; i++) {
		for (int j = 1; j < n - i; j++) {
			int t = 0;

			// sum W
			for (int k = 1; k <= i; k++)
				for (int l = 1; l <= m; l++)
					if (a[k][l] != 'W')
						t++;

			// sum B
			for (int k = 1; k <= j; k++)
				for (int l = 1; l <= m; l++)
					if (a[i + k][l] != 'B')
						t++;

			// sum R
			for (int k = 1; k <= n - i - j; k++)
				for (int l = 1; l <= m; l++)
					if (a[i + j + k][l] != 'R')
						t++;

			ans = min(ans, t);
		}
	}
	cout << ans;
	return 0;
}
